package cn.stronglink;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;

import cn.stronglink.asset.model.RfidState;

public class Test11 {

	
	
	public static void main(String[] args) {
		//盘点
		List<RfidState> inventoryRfidList = new ArrayList<RfidState>();
		RfidState a1 = new RfidState();
		a1.setRfidNo("EA0002DC");
		a1.setU(24);
		a1.setRackConverCode("1010F7");
		inventoryRfidList.add(a1);
		RfidState  rf1 = new RfidState();
		rf1.setRfidNo("EA000261");
		rf1.setU(16);
		rf1.setRackConverCode("1010F7");
		inventoryRfidList.add(rf1);
	
		//台账
		List<RfidState> exsitRfidList = new ArrayList<RfidState>();
		
		
		RfidState  rf2 = new RfidState();
		rf2.setRfidNo("EA0002DC");
		rf2.setU(21);
		rf2.setRackConverCode("1010F7");
		exsitRfidList.add(rf2);
		compareInventorySheet(inventoryRfidList,exsitRfidList);
		
	}
	
	// inventoryRfidList 盘点设备
	
	// exsitRfidList 台账设备
	
	public static void compareInventorySheet(List<RfidState> inventoryRfidList, List<RfidState> exsitRfidList) {
		// 不同
		Collection<String> diffentReturn = new LinkedList<String>();
		
		//相同
		Collection<String> asReturn = new LinkedList<String>();
		
		Collection<RfidState> overData = new HashSet<RfidState>();
		Collection<RfidState> lossData = new HashSet<RfidState>();
		Collection<RfidState> differentData = new HashSet<RfidState>();
		Collection<RfidState> normalData = new HashSet<RfidState>();
		
		List<RfidState> max =inventoryRfidList;
		List<RfidState> min =exsitRfidList;
		if(max.size()<min.size()){
			max=exsitRfidList;
			min=inventoryRfidList;
		}
		
		//
	     Map<String,Integer> map = new HashMap<String,Integer>(max.size());
	     for (RfidState object : max) {
	         map.put(object.getRfidNo(), 1);
	     }
	     for (RfidState object : min) {
	         if(map.get(object.getRfidNo())==null)
	         {
	        	 diffentReturn.add(object.getRfidNo());
	        	 if(max.size()==exsitRfidList.size()&&exsitRfidList.size()!=inventoryRfidList.size()){
	        		 // 如果max<min 说明 max=bb为台账，  min=aa 为盘点
	        		 // 此时盘点的不在台账中 为盘盈
	        		 overData.add(object);
	        		 
	        	 }else{
	        		// 此时说明 max=aa为盘点，     min=bb 为台账
	        		 // 此时台账不在盘点中  为盘亏
	        		 lossData.add(object);
	        	 }
	        	 
	         }else{
	             map.put(object.getRfidNo(), 2);
	         }
	     }
	     
	     
	     
	     // inventoryRfidList所有
	     Map<String,RfidState> inventoryRfidListmap = new HashMap<String,RfidState>(inventoryRfidList.size());
	     for (RfidState object : inventoryRfidList) {
	    	 inventoryRfidListmap.put(object.getRfidNo(), object);
	     }
	     
	     
	     //exsitRfidList 所有
	     Map<String,RfidState> exsitRfidListmap = new HashMap<String,RfidState>(exsitRfidList.size());
	     for (RfidState object : exsitRfidList) {
	    	 exsitRfidListmap.put(object.getRfidNo(), object);
	     }
	     
	     for (Map.Entry<String, Integer> entry : map.entrySet()) {
	         if(entry.getValue()==1)
	         {
	        	 //diffentReturn.add(entry.getKey());
	        	 if(max.size()==exsitRfidList.size()&&exsitRfidList.size()!=inventoryRfidList.size()){
	        		 // 如果max<min 说明 max=bb为台账，  min=aa 为盘点
		        		// 此时entry.getvalue==1的 说明     盘点中没有的此时为盘亏
	        		 lossData.add(exsitRfidListmap.get(entry.getKey()));
	        	 }else{
	        		// 此时说明 max=aa为盘点，     min=bb 为台账
		        		// 此时entry.getvalue==1的 说明     台账中没有的 此时为盘盈
	        		 overData.add(inventoryRfidListmap.get(entry.getKey()));
	        		 
	        	 }
	         }
	         if(entry.getValue()==2){
	        	 asReturn.add(entry.getKey());
	         }
	     }
	     
	     /**
	      * 最后再判断 相同的里边有没有差异 asReturn 
	      */
	     
	     for(Iterator<String> iter = asReturn.iterator(); iter.hasNext();){
	    	 String rfid =(String) iter.next();
	    	 RfidState inventoryRfidListobj =inventoryRfidListmap.get(rfid);
	    	 RfidState exsitRfidListobj =exsitRfidListmap.get(rfid);
	    	 
	    	 if(inventoryRfidListobj.getU()!=exsitRfidListobj.getU()){
	    		 //差异
	    		 differentData.add(inventoryRfidListmap.get(rfid));
	    		 
	    	 }else{
	    		 normalData.add(inventoryRfidListmap.get(rfid));
	    	 }
	    	 
	     }
	     
	     System.out.println("-------------------------循环打印-------------");
	     System.out.println("盘盈------》");
	     for(Iterator<RfidState> iter = overData.iterator(); iter.hasNext();){
	    	 RfidState obj = (RfidState) iter.next();
	    	 System.out.println(obj.getRfidNo()+"盘盈");
	    	 
	     }
	     System.out.println("盘亏------》");
	     for(Iterator<RfidState> iter = lossData.iterator(); iter.hasNext();){
	    	 RfidState obj = (RfidState) iter.next();	    	 
	    	 System.out.println(obj.getRfidNo()+"盘亏");
	    	 
	     }
	     System.out.println("差异------》");
	     for(Iterator<RfidState> iter = differentData.iterator(); iter.hasNext();){
	    	 RfidState obj = (RfidState) iter.next();
	    	 System.out.println(obj.getRfidNo()+"差异");
	    	 
	     }
	     
	     System.out.println("正常------》");
	     for(Iterator<RfidState> iter = normalData.iterator(); iter.hasNext();){
	    	 RfidState obj = (RfidState) iter.next();
	    	 
	     }
	         
	}
	
	//测试分支切换
	
}
